import useEditorStore from '@/store/modules/editorStore'
import { onMounted, onUnmounted } from 'vue'
const initPageClose = () => {
  const editorStore = useEditorStore()
  //定义一个函数，用于处理beforeunload事件
  const closeFn = (callBack: () => void) => {
    return (e: Event) => {
      e.preventDefault()
      callBack()
    }
  }

  //定义一个函数，用于处理beforeClose事件
  const beforeCloseHandel = () => {
    /**后续的逻辑可以写在这里 */
  }
  //在组件挂载时，添加beforeunload事件监听器
  onMounted(() => {
    //在组件挂载时，添加beforeunload事件监听器
    window.addEventListener('beforeunload', closeFn(beforeCloseHandel))
  })
  onUnmounted(() => {
    //在组件卸载时，移除beforeunload事件监听器
    window.removeEventListener('beforeunload', closeFn(beforeCloseHandel))
  })
}
export default initPageClose
